package com.fyzk.view;

import java.util.ArrayList;

public class ViewCallBack {
	
	private static ViewCallBack instance = null;

	private ViewCallBack(){}
	
	public static ViewCallBack getInstance(){
		if(instance == null){
			instance = new ViewCallBack();
		}
		return instance;
	}
	
	public interface CountDownInterface {
		void countDown();
	}
	
	public ArrayList<CountDownInterface> countDownObjs = new ArrayList<ViewCallBack.CountDownInterface>();
	
	public void AttachCountDownObj(CountDownInterface obj){
		if(!countDownObjs.contains(obj)){
			countDownObjs.add(obj);
		}
	}
	public void DettachCountDownObj(CountDownInterface obj){
		countDownObjs.remove(obj);
	}
	
	public void countDown(){
		for(CountDownInterface obj : countDownObjs ){
			obj.countDown();
		}
	}
	
	public String refreshTimeLeft(long count_down) {
		if(count_down<=0){
			return "正在获取中……";
		}
		
		long time = (long) count_down / 1000;// / 1000;
		int day = (int) time / 3600 / 24;
		int hour = (int) time / 3600 % 24;
		int minute = (int) time / 60 % 60;
		int second = (int) time % 60;
		StringBuffer str = new StringBuffer();
//		str.append("投注截至：");
		if(day>0){
			str.append(day).append("天").append(hour).append("小时");
		}else if(hour > 0){
			str.append(hour).append("小时").append(minute).append("分");
		}else{
			str.append(minute).append("分").append(second).append("秒");
		}
		return (str.toString());
	}
	
	
	

}
